<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>高校宿舍管理系统-更改密码</title>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="../layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layui/css/public.css" media="all">
    <link rel="stylesheet" href="../layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style type="text/css">
        .layui-form-item {
            width: 450px;
            text-align: center;
            margin-top: 20px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-verify="required" autocomplete="off"
                           lay-reqtext="旧的密码不能为空" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-verify="required" autocomplete="off"
                           lay-reqtext="新密码不能为空" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-verify="required" autocomplete="off"
                           lay-reqtext="确认密码要与新密码一致" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-radius" type="button" lay-submit lay-filter="saveBtn">
                        <span class="layui-icon layui-icon-ok"></span>确认保存
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../layui/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data);
            var new_password = data.field.new_password;
            var again_password = data.field.again_password;
            if (!(new_password === again_password)) {
                layer.msg("确认密码与新密码不一致！", {icon: 0});
                return false;
            }
            var url = "/updatePassword.action";
            var param = JSON.stringify(data.field);
            $.post(url, {"param": param}, function (result) {
                if (result.success) {
                    layer.msg(result.msg, {icon: 1}, function () {
                        miniTab.deleteCurrentByIframe();
                    });
                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }, "json");
            return false;
        });
    });
</script>
</body>
</html>